#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2020-11-09 9:31 上午
# @Author  : yangdy
# @File    : 2020-11-09.973.最接近原点的 K 个点
# @Software: PyCharmCE
from tools.my_methods import *


class Solution:
    def kClosest(self, points: List[List[int]], K: int) -> List[List[int]]:
        # if not points:
        #     return []
        #
        # def cal(pi):
        #     return points[pi][0] ** 2 + points[pi][1] ** 2
        #
        # data = [(i, points[i][0] ** 2 + points[i][1] ** 2) for i in range(len(points))]
        # data.sort(key=lambda x: x[1])
        # return list(map(lambda x: [points[x[0]][0], points[x[0]][1]], data[:K]))
        points.sort(key=lambda x: x[0] ** 2 + x[1] ** 2)
        return points[:K]
